<template>
    <div>
          <el-table
            :data="PaySuccessTable"
            style="width: 100%">

            <el-table-column
            label="ID"
            width="60">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.id }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="商品详情"
            width="120">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <router-link :to="'/detail?category='+scope.row.category+'&id='+scope.row.product_id" style="color:black">
                        <img :src="require('@/assets/'+scope.row.category+'/'+scope.row.product_id+'/1.jpg')" style="width: 100px; height: 100px"><br>
                    </router-link>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="订单支付人"
            width="100">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.username }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="订单归属商铺"
            width="150">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.shopname }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="商品名称"
            width="200">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.title }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="商品数量"
            width="100">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.product_nums }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="商品总价"
            width="100">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.price }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="订单状态"
            width="100">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.status }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column
            label="订单号"
            width="250">
            <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.outtradeno }}</el-tag>
                </div>
            </template>
            </el-table-column>

            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                    size="mini"
                    type="danger"
                    style="margin-left:10px"
                    @click="handleAccept(scope.row)">退款</el-button>
                </template>
            </el-table-column>


        </el-table>
    </div>
</template>

<script>
export default {
    name: "refund",
    data(){
        return{
            PaySuccessTable: []
        }
    },
    methods: {
      handleAccept(row){
            this.$axios.post("/api/refund",this.$querystring.stringify({
            out_trade_nos:row.outtradeno,
            total_amount:row.price,
            id: row.id
            })).then(reponse=>{
            console.log(reponse);
            if(reponse.data == true){
               alert("退款成功")
            }else{
                alert("系统错误")
            }
        })
      }
    },
    mounted(){
        if(this.$cookies.get("refund_second") != 'ok'){
            alert("无权限");
            this.$router.push("/adminindex")
        }else{
            this.$axios.get("/api/getAllPaySuccessOrders").then(res=>{
                this.PaySuccessTable = res.data
            });
        }
    },
}
</script>

<style scoped>

</style>